package view

import (
	"cloudops/src/web/middleware"
	"github.com/gin-gonic/gin"
	"time"
)

// 配置路由
func ConfigRouter(r *gin.Engine) {
	// 定义一个组
	// 共享中间件
	//base := r.Group("/basic-api")
	base := r.Group("/")
	{
		base.GET("/ping", ping)
		//base.GET("/now", getNowTs)
		//base.GET("/long", longRequest)
		base.POST("/login", UserLogin)

	}
	// 登录后才能访问的路由
	afterLoginApiGroup := r.Group("/api")
	afterLoginApiGroup.Use(middleware.JWTAuthMiddleware()).Use(middleware.CasbinRbacMiddleware())
	{
		afterLoginApiGroup.GET("/getUserInfo", getUserInfoAfterLogin)
		afterLoginApiGroup.GET("/getPermCode", getPermCode)
	}
	// 底座模块
	systemApiGroup := afterLoginApiGroup.Group("/system")
	{
		// 菜单相关
		systemApiGroup.GET("/getMenuList", getMenuList)
		systemApiGroup.GET("/getMenuListAll", getMenuListAll)
		systemApiGroup.POST("/updateMenu", updateMenu)
		systemApiGroup.POST("/createMenu", createMenu)
		systemApiGroup.DELETE("/deleteMenu/:id", deleteMenu)

		// 角色相关
		systemApiGroup.GET("/getRoleListAll", getRoleListAll)
		systemApiGroup.POST("/createRole", createRole)
		systemApiGroup.POST("/updateRole", updateRole)
		systemApiGroup.POST("/setRoleStatus", setRoleStatus)
		systemApiGroup.DELETE("/deleteRole/:id", deleteRole)

		// 用户相关
		systemApiGroup.POST("/createAccount", createAccount)
		systemApiGroup.POST("/accountExist", accountExist)
		systemApiGroup.POST("/updateAccount", updateAccount)
		systemApiGroup.POST("/changePassword", changePassword)
		systemApiGroup.GET("/getAccountList", getAccountList)
		systemApiGroup.GET("/getAllUserAndRoles", getAllUserAndRoles)
		systemApiGroup.DELETE("/deleteAccount/:id", deleteAccount)

		// API相关
		systemApiGroup.GET("/getApiList", getApiList)
		systemApiGroup.GET("/getApiListAll", getApiListAll)
		systemApiGroup.POST("/createApi", createApi)
		systemApiGroup.POST("/updateApi", updateApi)
		systemApiGroup.DELETE("/deleteApi/:id", deleteApi)
	}

	// 服务树模块
	streeApiGroup := afterLoginApiGroup.Group("/stree")
	{
		streeApiGroup.GET("/getStreeNodeList", getStreeNodeList)
		streeApiGroup.GET("/getStreeNodeSelect", getStreeNodeSelect)
		//streeApiGroup.GET("/getTopStreeNodes", getTopStreeNodes)
		streeApiGroup.GET("/getTopStreeNodes", getTopStreeNodesUseCache)
		streeApiGroup.POST("/createStreeNode", createStreeNode)
		streeApiGroup.DELETE("/deleteStreeNode/:id", deleteStreeNode)
		streeApiGroup.GET("/getChildrenStreeNodes/:pid", getChildrenStreeNodes)
		streeApiGroup.POST("/updateStreeNode", updateStreeNode)

		// ECS相关
		streeApiGroup.GET("/getResourceEcsUnbindList", getResourceEcsUnbindList)
		streeApiGroup.POST("/bindEcsToStreeNode", bindEcsToStreeNode)
		streeApiGroup.POST("/unBindEcsToStreeNode", unBindEcsToStreeNode)

		// 所有资源展示
		streeApiGroup.GET("/fetchResourceByNode", fetchResourceByNode)

		// elb相关
		streeApiGroup.GET("/getResourceElbUnbindList", getResourceElbUnbindList)
		streeApiGroup.POST("/bindElbToStreeNode", bindElbToStreeNode)
		streeApiGroup.POST("/unBindElbToStreeNode", unBindElbToStreeNode)

		// rds相关
		streeApiGroup.GET("/getResourceRdsUnbindList", getResourceRdsUnbindList)
		streeApiGroup.POST("/bindRdsToStreeNode", bindRdsToStreeNode)
		streeApiGroup.POST("/unBindRdsToStreeNode", unBindRdsToStreeNode)
	}

	//工单模块
	workOrderApiGroup := afterLoginApiGroup.Group("/workorder")
	{
		// 流程管理相关
		workOrderApiGroup.POST("/createProcess", createProcess)
		workOrderApiGroup.GET("/getProcessList", getProcessList)
		workOrderApiGroup.POST("/updateProcess", updateProcess)
		workOrderApiGroup.DELETE("/deleteProcess/:id", deleteProcess)

		// 表单设计相关
		workOrderApiGroup.POST("/createFormDesign", createFormDesign)
		workOrderApiGroup.GET("/getFormDesignList", getFormDesignList)
		workOrderApiGroup.POST("/updateFormDesign", updateFormDesign)
		workOrderApiGroup.DELETE("/deleteFormDesign/:id", deleteFormDesign)

		// 工单模版管理
		workOrderApiGroup.GET("/getWorkOrderTemplateList", getWorkOrderTemplateList)
		workOrderApiGroup.POST("/createWorkOrderTemplate", createWorkOrderTemplate)
		workOrderApiGroup.POST("/updateWorkOrderTemplate", updateWorkOrderTemplate)
		workOrderApiGroup.DELETE("/deleteWorkOrderTemplate/:id", deleteWorkOrderTemplate)
		workOrderApiGroup.GET("/getWorkOrderTemplateDetail/:id", getWorkOrderTemplateDetail)

		// 工单申请
		workOrderApiGroup.POST("/createWorkOrderInstance", createWorkOrderInstance)
		workOrderApiGroup.POST("/approvalWorkOrderInstance/:id", approvalWorkOrderInstance)
		workOrderApiGroup.POST("/actionWorkOrderInstance/:id", actionWorkOrderInstance)
		workOrderApiGroup.POST("/commentWorkOrderInstance/:id", commentWorkOrderInstance)
		workOrderApiGroup.GET("/getWorkOrderInstanceList", getWorkOrderInstanceList)
		workOrderApiGroup.GET("/getWorkOrderInstanceOne/:id", getWorkOrderInstanceOne)
		workOrderApiGroup.POST("/urgeWorkOrderInstance/:id", urgeWorkOrderInstance)
	}

	// 任务执行模块
	jobExecApiGroup := afterLoginApiGroup.Group("/jobexec")
	{
		jobExecApiGroup.POST("/createJobTask", createJobTask)
		jobExecApiGroup.GET("/getJobTaskList", getJobTaskList)
		jobExecApiGroup.POST("/actionJobTaskOne/:id", actionJobTaskOne)
		jobExecApiGroup.GET("/getJobExecResultByJobId", getJobExecResultByJobId)

		jobExecApiGroup.GET("/getJobExecScriptList", getJobExecScriptList)
		jobExecApiGroup.GET("/getJobExecScriptSelect", getJobExecScriptSelect)
		jobExecApiGroup.GET("/getJobExecScriptOne/:id", getJobExecScriptOne)
		jobExecApiGroup.POST("/createJobExecScript", createJobExecScript)
		jobExecApiGroup.POST("/updateJobExecScript", updateJobExecScript)
		jobExecApiGroup.DELETE("/deleteJobExecScript/:id", deleteJobExecScript)
		jobExecApiGroup.GET("/getJobTaskOne/:id", getJobTaskOne)
	}
}

// 测试路由
func getNowTs(c *gin.Context) {
	c.String(200, time.Now().Format("2006-01-02 15:04:05"))
}

/*func longRequest(c *gin.Context) {
	fmt.Println("longRequest请求开始，休息5秒")
	time.Sleep(time.Second * 5)
	c.String(200, time.Now().Format("2006-01-02 15:04:05"))
}
*/
